package com.lizhi.yun.system.stand.handler;/**
 * @program: sfrobot-html
 * @name StandPtInfoHnadler
 * @description: 患者信息
 * @author: lizhi
 * @create: 2020-04-24 16:10
 */

import com.lizhi.client.RestClientService;
import com.lizhi.common.yun.entity.ListResponseResult;
import com.lizhi.common.yun.enums.ServiceEnum;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.base.BaseHandler;
import com.lizhi.yun.base.common.RoleOrganUtils;
import com.lizhi.yun.db.dao.UppUserDao;
import com.lizhi.yun.db.pojo.UppUserPOJO;
import com.lizhi.yun.system.stand.enums.StandServiceEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 *@program: sfrobot-html
 *@name StandPtInfoHnadler
 *@description: 患者信息
 *@author: lizhi
 *@create: 2020-04-24 16:10
 */
@Slf4j
@Service
public class StandPtInfoHnadler extends BaseHandler {

    @Resource
    private UppUserDao uppUserDao;

    @Resource
    private RestClientService restClientService;

    /**
     *功能描述 分页查询
     * @author lizhi
     * @date 2020/4/24
     * @param map:
     * @return com.lizhi.common.base.PagerView<com.lizhi.db.pojo.StandPtInfoPOJO>
     */
    public ListResponseResult doMain(Map<String, Object> map, HttpServletRequest request) {
        String userAcct = request.getHeader("userAcct");
        UppUserPOJO uppUserPOJO = uppUserDao.selectById(userAcct);
        /*判断医院*/
        map.put("hospitalIds", RoleOrganUtils.listOrganIds(uppUserPOJO.getOrganIds()));

        String result = restClientService.postStringToService(StandServiceEnum.HBSF_STAND_PATIENT_INFO.getEnName(), StandServiceEnum.HBSF_STAND_PATIENT_INFO.getEnValue(), SamJsonUtil.toJson(map));
        return SamJsonUtil.toObject(result, ListResponseResult.class);
    }


    /**
     *功能描述 根据String ptId查询患者信息
     * @author lizhi
     * @date 2020/4/24
     * @param ptId:
     * @return com.lizhi.db.pojo.StandPtInfoPOJO
     */
    public ListResponseResult selectById(String ptId, String hospitalId, String hospitalSystemId){
        Map<String, Object> map = new HashMap<>();
        map.put("ptId", ptId);
        map.put("hospitalId", hospitalId);
        map.put("hospitalSystemId", hospitalSystemId);
        String result = restClientService.postStringToService(ServiceEnum.HBSF_YUN.getEnName(), ServiceEnum.HBSF_YUN.getEnValue(), SamJsonUtil.toJson(map));
        return SamJsonUtil.toObject(result, ListResponseResult.class);
    }
}
